<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //1.promise.all()方法: 可以传入多个promise对象,获取所有promise对象的结果
      let p1 = new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve(111);
        }, 1000);
      });
      let p2 = new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve(222);
        }, 3000);
      });
      let p3 = new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve(333);
          // reject("err222");
        }, 2000);
      });
      //会等待所有结果都执行完毕 再返还所有的结果
      //所有的promise对象必须都是成功状态,才能获取所有的promise对象的结果
      Promise.all([p1, p2, p3]).then(
        (res) => {
          console.log(res);
        },
        (err) => {
          console.log(err);
        }
      );
    </script>
  </body>
</html>
